package com.lqk.iterator;

import java.util.Iterator;
import java.util.List;

/**
 * @author lqk
 * @date 2021/12/9 20:06
 */
public class OutputImpl {
    // 学院集合
    List<College> collegeList;

    public OutputImpl(List<College> collegeList) {
        this.collegeList = collegeList;
    }

    // 遍历所有学院，调用 printDepartment 输出各个学院的系
    public void printCollege(){
        // 从 collegeList 取出所有学院
        Iterator<College> iterator = collegeList.iterator();
        while (iterator.hasNext()){
            // 取出学院
            College college = iterator.next();
            System.out.println("======"+college.getName()+"======");
            printDepartment(college.createIterator());  // 得到对应的迭代器
        }
    }

    // 输出，学院输出系
    public void printDepartment(Iterator iterator){
        while (iterator.hasNext()){
            Department next = (Department) iterator.next();
            System.out.println(next.getName());
        }
    }
}
